package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 数据统计业务层
 * @author GY
 * @version V1.0
 * @date 2025-01-15 11:52
 */
@Service
@RequiredArgsConstructor
public class ReportServiceImpl implements ReportService {

    private final EmpMapper empMapper;
    private final StudentMapper studentMapper;
    @Override
    public JobOption empFindByJob() {
        List<Map<String ,Object>> data = empMapper.empFindByJob();
        List<Object> jobList = data.stream().map(o -> o.get("job")).toList();
        List<Object> dataList = data.stream().map(o -> o.get("num")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> empFindByGender() {
        return empMapper.empFindByGender();
    }

    @Override
    public List<Map<String, Object>> studentFindByDegree() {
        return studentMapper.studentFindByDegree();
    }

    @Override
    public StudentOption studentFondByClazz() {
        List<Map<String ,Object>> data =studentMapper.studentFondByClazz();
        List<Object> clazzList = data.stream().map(o -> o.get("clazz")).toList();
        List<Object> dataList = data.stream().map(o -> o.get("num")).toList();
        return new StudentOption(clazzList,dataList);

    }
}
